package com.town.garden.service.impl;

import com.town.garden.constant.GlobalConstant;
import com.town.garden.entiy.request.SearchPlaybackRtspUrlRequest;
import com.town.garden.entiy.response.SearchPlaybackRtspUrlResponse;
import com.town.garden.enums.NVRApiEnum;
import com.town.garden.propertites.NvrProperties;
import com.town.garden.service.NvrPlaybackRtspUrlService;
import com.town.garden.storage.NvrSessionStorage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @Description
 * @E-mail cwm3412638@163.com
 * @Author cwm
 * @Date 2022/5/16
 */
@Service
@Slf4j
public class NvrPlaybackRtspUrlServiceImpl implements NvrPlaybackRtspUrlService {
    @Autowired
    private NvrProperties nvrProperties;
    @Autowired
    private RestTemplate restTemplate;

    @Override
    public ResponseEntity<SearchPlaybackRtspUrlResponse> searchPlaybackRtspUrl(SearchPlaybackRtspUrlRequest searchPlaybackRtspUrlRequest) {
        //拼接请求url
        final String url = GlobalConstant.HTTPS_PREFIX + nvrProperties.getNvrServerIp() + NVRApiEnum.PLAYBAC_RTSPK_URL.getUrl();
        final HttpEntity<?> entity = new HttpEntity<>(searchPlaybackRtspUrlRequest, NvrSessionStorage.headers);
        try {
            return restTemplate.exchange(url, HttpMethod.POST, entity, SearchPlaybackRtspUrlResponse.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
